#include "curveitem.h"

CurveItem::CurveItem(QGraphicsItem *parent) : QGraphicsLineItem (parent)
{

}

CurveItem::CurveItem(qreal x1, qreal y1, qreal x2, qreal y2, QGraphicsItem *parent)
    : QGraphicsLineItem (x1, y1, x2, y2, parent)
{
    QPointF sp(x1, y1);
    QPointF ep(x2, y2);
    QPointF c1((x1 + x2) / 2, y1);
    QPointF c2((x1 + x2) / 2, y2);
    path = QPainterPath(sp);
    path.cubicTo(c1, c2, ep);
}

CurveItem::CurveItem(const QLineF &line, QGraphicsItem *parent)
    : QGraphicsLineItem (line, parent)
{
    qreal x1 = line.x1(),
            x2 = line.x2(),
            y1 = line.y1(),
            y2 = line.y2();
    QPointF sp(x1, y1);
    QPointF ep(x2, y2);
    QPointF c1((x1 + x2) / 2, y1);
    QPointF c2((x1 + x2) / 2, y2);
    path = QPainterPath(sp);
    path.cubicTo(c1, c2, ep);
}

void CurveItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget){
    Q_UNUSED(option);
    Q_UNUSED(widget);
    painter->setPen(QGraphicsLineItem::pen());
    painter->drawPath(path);
}
